#ifndef GROUP_VIEW_H
#define GROUP_VIEW_H

#include <QWidget>
#include "server/server.h"
#include "DataPro/datapro.h"
#include "Charts/creatcharts.h"
#include "Beans/psychologyindex.h"
#include "group.h"
#include "QTimer"
#include "DataBase/mysql.h"
#include "mybutton.h"
#include "qdatetime.h"
namespace Ui {
class Group_view;
}
typedef  struct DATA_INFO_T
{
    QString IP;//IP地址
    QString UserID;
    QString UserName;
    int socketDescriptor;
    int btn_num;//用户按钮编号，根据ip地址快速找到对应的按钮去显示测量指标
    QList<double>Spress_List;//用于显示个人压力分布
    //一下指标用于显示平均模式下统计分布
    double HR;
    double Ox;
    double Fatigure;
    double Depress;
    double Ansiety;
    double Ballance;
    double Activity;
    double AntiPress;
    double SDP;
    double PhysicalMentalHealth;
    myButton *mybtn;//用于在哪个按钮去显示对应的结果
    //个人结果存储
    int RR[300];
    int rrValidLen;
    double hrvindex[28];
    bool iseleoff;

}DATA_INFO;
typedef QHash<QString, DATA_INFO> QHashDataInfo;
typedef QHash<QString, DATA_INFO>::iterator QHashDataInfoIterator;
class Group_view : public QWidget
{
    Q_OBJECT

public:
    explicit Group_view(QWidget *parent = nullptr);
    ~Group_view();
    void paintEvent(QPaintEvent *event);
    void initialVariable();
    void initServer();
    void initialSlots();
    void initialWaveChart();
    QList<int> Tongji(int type,QList<double>index);
    double mean_List(QList<double>l);



private:
    Ui::Group_view *ui;
    QHashDataInfo hash_data_info;
    int btn_num;
    DataPro dataPro;
    DATA_INFO data_Info;
    CreatCharts cc;
    QChart *hr_Chart;
    QChart *ox_Chart;
    QChart *mp_Chart;
    QChart *mp_PieChart;
    QChart *hrvHist_BarChart;
    QChart *hrvScatterChart;
    QChart *hrvARAreaChart;
    QChart *hrvBallanceChart;



    QChart *a_hr_Chart;
    QChart *a_ox_Chart;
    QChart *a_mp_Chart;
    QChart *a_fatigure_Chart;
    QChart *a_depress_Chart;
    QChart *a_ansiety_Chart;
    QChart *a_ballance_Chart;
    QChart *a_activity_Chart;

    QTimer *timer_UpdataChart;//更新平均图表
    int widget_btNum=0;
    QHashUserTable m_userTableHash;
    QString TaskID,Type,Scene;
    int NeedTime;
    QDateTime startTime;
    //团体模式下所有人的平均数据记录，用于报告中波形趋势图的绘制
    QList<double>PhysicalMentalHealth_list_A;

    QHash<QString,QString>btnBindIP;
private slots:
    void receivedMsg(QJsonObject & json);

    void addNewClient(QString);

    void removeClient(QString);

    void MyButtionClickeListener1();
    void MyButtionClickeListener2();
    void MyButtionClickeListener3();
    void MyButtionClickeListener4();
    void MyButtionClickeListener5();
    void MyButtionClickeListener6();
    void MyButtionClickeListener7();
    void MyButtionClickeListener8();
    void MyButtionClickeListener9();
    void MyButtionClickeListener10();
    void MyButtionClickeListener11();
    void MyButtionClickeListener12();
    void MyButtionClickeListener13();
    void MyButtionClickeListener14();
    void MyButtionClickeListener15();
    void MyButtionClickeListener16();
    void MyButtionClickeListener17();
    void MyButtionClickeListener18();
    void MyButtionClickeListener19();
    void MyButtionClickeListener20();

    void on_btn_group_all_clicked();

    void on_pushButton_exit_clicked();



    void update_a_Data();

    void on_btn_group_average_clicked();

    void on_pushButton_end_clicked();

    void getUserTableInfo(QHashUserTable m_user,QString TaskID,QString Type,QString Scene,int time);


signals:
    void command_toClient(int type,QJsonObject json);
};

#endif // GROUP_VIEW_H
